Skip to content

refactor: PlatformRegistry pattern#18

Merged
oktapp-aperture-okta[bot] merged 8 commits intomasterfrom
jp-platform-registry
Mar 12, 2026
Merged

refactor: PlatformRegistry pattern#18
oktapp-aperture-okta[bot] merged 8 commits intomasterfrom
jp-platform-registry

Conversation

@jaredperreault-okta
Copy link
Contributor

No description provided.

Comment on lines +9 to +12
export interface PlatformDependencies {
TimeCoordinator: TimeCoordinator;
DPoPSigningAuthority: DPoPSigningAuthority;
}
Copy link

@alexchen-okta alexchen-okta Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking ahead, just curious if is there anything currently in the plan to extend this and support any specific additional global dependencies? i.e. there any scope for telemetry or a logger for errors or certain oauth operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Telemetry and Loggers are great examples of things we could put in here. There probably won't be specific OAuth operations, but perhaps singletons to enable OAuth operations, like the DPoPSigningAuthority for example.

I will probably add things here I expect to get implemented at a platform level, like TokenStorage. The advantage is the default In-Memory Token storage impl won't be included in the bundle

Comment on lines +20 to +40
* For example, the {@link TimeCoordinator} should be globally available to be a
* centralized entity to perform all time calculations. Registering the {@link TimeCoordinator}
* as a {@link Platform} dependency enables consumers to access the {@link TimeCoordinator} via
*
* @example
* ```
* import { Platform } from '@okta/auth-foundation';
* const currentTime = Platform.TimeCoordinator.now();
* ```
*
* To enable tree-shaking and prevent including default implementations (bundle bloat) which
* will be instanceously overwritten, default implemenations can be selectively included.
*
* @remarks
* Use `import * from '@okta/auth-foundation'` for standard usage, including all default platform
* dependency implementations.
*
* Use `import * from '@okta/auth-foundation/core'` for deeper customizations of platform dependencies,
* this does not include any default implementations. {@link PlatformRegistryError} will be thrown if
* a dependency is used before an implementation is provided
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the usage is very clearly explained here

Comment on lines +16 to +19
/**
* A singleton registry of globally-available singleton dependencies which can
* provide platform-specific default implementations and enable overriding as needed
*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first time i read the class name PlatformRegistry, i assumed more of a registry of platforms i.e. browsers/node rather than a registry of dependencies that can be overriden to support different platforms. i can't come up with a better name myself but just wanted to give feedback in case you had a better name in mind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard

* ```
*
* To enable tree-shaking and prevent including default implementations (bundle bloat) which
* will be instanceously overwritten, default implemenations can be selectively included.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo on implemenations


/** @internal */
export const DefaultDPoPSigningAuthority: DPoPSigningAuthority = new DPoPSigningAuthorityImpl(new DPoPStorage.MemoryStore());
/** @internal - Use `Platform.DPoPSigninAuthority instead */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing closing backtick

* import { Platform } from '@okta/auth-foundation/core'; // ensure "/core" is imported specifically
*
* Platform.registerDefaultsLoader(() => ({
* TimeCoordinator: MyCustomTimeCoordinator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to include all of the PlatformDependencies i.e. including the DPoPSigningAuthority and DPoPNonceCache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I guess the doc comments are clear 😅

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i missed the comment 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment in response to your feedback. "guess the doc comments are clear" meant, you clearly understand the dependencies/required inputs (otherwise you wouldn't have caught that)

@jaredperreault-okta jaredperreault-okta marked this pull request as ready for review March 12, 2026 12:48
@oktapp-aperture-okta oktapp-aperture-okta bot merged commit 424ee52 into master Mar 12, 2026
1 check passed
@oktapp-aperture-okta oktapp-aperture-okta bot deleted the jp-platform-registry branch March 12, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants